// @author: caoshi
// @date: 2021-06-06 20:17
package v1

import (
	"demo08_paramsbind/src/model"
	"demo08_paramsbind/src/util/captcha"
	"fmt"
	"github.com/gin-contrib/sessions"
	"github.com/gin-gonic/gin"
	"strings"
)

// 用户登录
func Login(c *gin.Context) {
	var userJson model.Login
	err := c.ShouldBindJSON(&userJson)
	if err != nil {
		fmt.Println("获取参数失败")
	}
	session := sessions.Default(c)
	sessionValue := session.Get(SessionId)
	fmt.Println(">>>>>>>>>>>> session中存储的captchaId ", sessionValue)
	fmt.Println(">>>>>>>>>>> 用户输入的登录信息 ", userJson)
	capId := fmt.Sprintf("%v", sessionValue)
	pass := captcha.VerifyCaptcha(capId, userJson.Vcode)

	if strings.Compare(userJson.Username, "zs") == 0 &&
		strings.Compare(userJson.Password, "123") == 0 {

		if pass {
			fmt.Println("验证码输入正确")
		} else {
			fmt.Println("验证码输入错误")
		}

	}

}

func Register(c *gin.Context) {
	fmt.Println("用户注册 ...")
}

func ChangePassword(c *gin.Context) {
	fmt.Println("用户修改密码")
}
